home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Source / 20-NetworkServices / ftp / ftp-config.frm.z / ftp-config.frm
Encoding:
Text File  |  1997-07-30  |  9.5 KB  |  331 lines

  1. #!/usr/bin/perl5
  2. #
  3. # ftp-config.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: ftp-config.frm,v 1.31 1997/06/19 22:25:14 shotes Exp $
  21.  
  22. # Form validation:  Inactivity timeout > 60
  23. #
  24. # Configuration file:  /etc/inetd.conf
  25.  
  26. *MINTIMEOUT = \240;
  27. *MAXTIMEOUT = \7200;
  28.  
  29. require "/usr/OnRamp/lib/OnRamp.pm";
  30. require "/usr/OnRamp/lib/java.pm";
  31.  
  32. $myname = "ftp-config.cgi";
  33. $conf = "/etc/inetd.conf";
  34. $dummy = "/etc/inetd.conf.tmp";
  35.  
  36. $title = "FTP Server";
  37.  
  38. if ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla\/2/) { $br_index = 1; }
  39. else { $br_index = 0; }
  40.  
  41. $js = 
  42. "br_index = $br_index;
  43. $js_check_int
  44. $js_standard
  45. $js_error_box
  46. function checkForm(form) {
  47.     if (form.eftp[br_index].checked) {
  48.         if (!testTimeout(form)) return (false);
  49.     } return (true);
  50. }
  51. function testTimeout(form) {
  52.     Ctrl = form.dto;
  53.     start = 0;  
  54.     while (Ctrl.value.charAt(start) == ' ') { start++; }
  55.     end = Ctrl.value.length-1; while (Ctrl.value.charAt(end) == ' ') { end--; }
  56.     time = Ctrl.value.substring(start,end+1);
  57.     for(i = 0; i < time.length; i++) { 
  58.         num = parseInt(time.charAt(i)); 
  59.         if (! checkInt(num, 10)) { 
  60.             errorBox (Ctrl, \"Timeout must be an integer value.\"); 
  61.             return (false); 
  62.         } 
  63.     }
  64.     num = parseInt(time);
  65.     if (num < 240 || num > 7200) { 
  66.         errorBox (Ctrl, \"Inactivity timeout must be between \\n240 and 7200 seconds.\"); 
  67.         return (false); 
  68.     }
  69.     return (true);
  70. }";
  71.  
  72.  
  73. print "Content-type: text/html\n\n";
  74.  
  75. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  76. @fields = split('&',$buffer);
  77.  
  78. &getValues;
  79.  
  80. foreach (@fields) {
  81.   @line = split('=',$_);
  82.   $line[1] =~ tr/+/ /; 
  83.   $fld{$line[0]} = $line[1];
  84.   }
  85.  
  86. if (%fld) {
  87.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  88.     $help =~ s/cgi$/hlp/;
  89.     exec $help if ($fld{'help'} eq "Help");
  90.  
  91.     if ($fld{'doit'} eq 'Ok') {
  92.         &formValidation;
  93.         if ($fld{'eftp'} eq 'Yes') { &enableFTP; }
  94.         else { &disableFTP; }
  95.     &getValues;
  96.     }
  97. }
  98.  
  99. &generic;
  100.  
  101. sub formValidation {
  102.     if ($fld{'dto'}) {
  103.         local ($error) = &check_int($fld{'dto'}, $MINTIMEOUT, $MAXTIMEOUT);
  104.  
  105.         &error("Timeout must be an integer value") if $error == 1;
  106.  
  107.         &error("Inactivity timeout must be between $MINTIMEOUT and $MAXTIMEOUT seconds.")
  108.             if $error > 1;
  109.     }
  110.     else { $fld{'dto'} = 900; } 
  111. }
  112.  
  113. sub error {
  114.     &error_block($_[0]);
  115.     $val{'dto'} = $fld{'dto'};
  116.     $val{'logf'} = $fld{'logf'};    
  117.     $val{'eftp'} = $fld{'eftp'};    
  118.     &generic;
  119.     exit 0;
  120. }
  121.  
  122. sub enableFTP {
  123.     $value = "ftp\tstream\ttcp\tnowait\troot\t/usr/etc/ftpd\tftpd";
  124.     if ($fld{'logf'} eq 'Yes') { $value .= " -l"; }
  125.     if ($fld{'dto'} ne '900') { 
  126.         $value .= " -t" . $fld{'dto'}; }
  127.  
  128.     $or = $fld{'or'};
  129.     $ow = $fld{'ow'};
  130.     $oe = $fld{'oe'};
  131.  
  132.     $gr = $fld{'gr'};
  133.     $gw = $fld{'gw'};
  134.     $ge = $fld{'ge'};
  135.  
  136.     $tr = $fld{'tr'};
  137.     $tw = $fld{'tw'};
  138.     $te = $fld{'te'};
  139.  
  140.     $mask = &args_to_umask;
  141.  
  142.     if ($mask ne '022') { 
  143.         $value .= " -u" . $mask; }
  144.     
  145.     &putEntry($conf,"ftp",$value);
  146.     system("/etc/killall", "-HUP", "inetd");
  147.  
  148.     $message = "FTP daemon enabled.";
  149. }
  150.  
  151. sub disableFTP {
  152.     if ($val{'eftp'} eq "Yes") { 
  153.         &commentEntry($conf,"ftp"); 
  154.     system("/etc/killall", "-HUP", "inetd");
  155.  
  156.         $message = "FTP daemon disabled.";
  157.     }
  158. }
  159.  
  160. sub commentEntry {
  161.     local($file) = $_[0];
  162.     local($entry) = $_[1];
  163.     local($len) = length($entry);
  164.  
  165.     open(IN,"< $file");
  166.     open(OUT,"> $dummy");
  167.     while(<IN>) {
  168.         if ($entry eq substr($_,0,$len)) {
  169.             print OUT "# ",$_;
  170.         } else { print OUT $_; }
  171.     }
  172.     close(IN);
  173.     close(OUT);
  174.     rename($dummy,$file) || &error("Unable to rename to $file");
  175. }
  176.  
  177. sub putEntry { 
  178.     local($file) = $_[0];
  179.     local($key) = $_[1];
  180.     local($val) = $_[2];
  181.  
  182.     open(IN,"< $file");
  183.     open(OUT,"> $dummy");
  184.     local($found) = 0;
  185.     while(<IN>) {
  186.         if (/^$key/ || /^#\s*$key/) {
  187.             print OUT $val,"\n";
  188.             $found = 1;
  189.         } else { print OUT $_; }
  190.     }
  191.     if ($found == 0) { print OUT $val,"\n"; }
  192.     close(IN);
  193.     close(OUT);
  194.     rename($dummy,$file) || &error("Unable to rename to $file");
  195. }
  196.  
  197. sub umask_to_args {
  198.     local($toct);
  199.     $toct = oct($_[0]);
  200.  
  201.     @otdef = @owdef = @grdef = ();
  202.  
  203.     if (!($toct & 0400)) { $val{'or'} = ""; } else { $val{'or'} = "on"; }
  204.     if (!($toct & 0200)) { $val{'ow'} = ""; } else { $val{'ow'} = "on"; }
  205.     if (!($toct & 0100)) { $val{'oe'} = ""; } else { $val{'oe'} = "on"; }
  206.  
  207.     if (!($toct & 0040)) { $val{'gr'} = ""; } else { $val{'gr'} = "on"; }
  208.     if (!($toct & 0020)) { $val{'gw'} = ""; } else { $val{'gw'} = "on"; }
  209.     if (!($toct & 0010)) { $val{'ge'} = ""; } else { $val{'ge'} = "on"; }
  210.  
  211.     if (!($toct & 0004)) { $val{'tr'} = ""; } else { $val{'tr'} = "on"; }
  212.     if (!($toct & 0002)) { $val{'tw'} = ""; } else { $val{'tw'} = "on"; }
  213.     if (!($toct & 0001)) { $val{'te'} = ""; } else { $val{'te'} = "on"; }
  214. }
  215.  
  216. sub args_to_umask {
  217.     $umask = 0;
  218.     if ($te eq "") { $umask += 1; }
  219.     if ($tw eq "") { $umask += 2; }
  220.     if ($tr eq "") { $umask += 4; }
  221.     if ($ge eq "") { $umask += 10; }
  222.     if ($gw eq "") { $umask += 20; }
  223.     if ($gr eq "") { $umask += 40; }
  224.     if ($oe eq "") { $umask += 100;}
  225.     if ($ow eq "") { $umask += 200; }
  226.     if ($or eq "") { $umask += 400; }
  227.     if ($umask < 100 && $umask > 9) { $umask = "0" . $umask; }
  228.     elsif ($umask < 10) { $umask = "00" . $umask; }
  229.     return $umask;
  230. }
  231.  
  232. sub getValues {
  233.     $val{'dto'} = $default_dto = 900;
  234.     $mto = $default_mto = 7200;
  235.     $val{'logf'} = $default_logf = "No";
  236.     $default_logf = "Yes";
  237.     $val{'eftp'} = "No";        # only set this to "Yes" if we find line
  238.  
  239.     $val{'or'} = "";    $val{'ow'} = "";    $val{'oe'} = "";
  240.     $val{'gr'} = "";    $val{'gw'} = "on";    $val{'ge'} = "";
  241.     $val{'tr'} = "";    $val{'tw'} = "on";    $val{'te'} = "";
  242.  
  243.     if (open(INETD, "< $conf")) {
  244.              while (<INETD>) {
  245.         @args = split(/\s+/);
  246.         if ($args[0] ne "ftp") { next; }
  247.         $val{'eftp'} = "Yes";
  248.         while ($arg = pop(@args)) {
  249.                 if ($arg eq "-l") { $val{'logf'} = "Yes"; }
  250.                 elsif (substr($arg,0,2) eq "-t") { $val{'dto'} = substr($arg,2); }
  251.                 elsif (substr($arg,0,2) eq "-T") { $mto = substr($arg,2); }
  252.                 elsif (substr($arg,0,2) eq "-u") { umask_to_args(substr($arg,2)); }
  253.             }
  254.         }
  255.     }
  256.  
  257.        close(INETD);
  258. }
  259.  
  260. sub generic {
  261.     &js_title_block($title,$js);
  262.     &header_block($title);
  263.  
  264.     print "<i>$message</i><br>";
  265.     print "<form name=\"StandardForm\" action=$myname method=post onSubmit=\"return runSubmit()\">";
  266.  
  267.     print "<center><table cellpadding=5 width=450>\n";
  268.  
  269.     print "<tr><th align=left>Enable FTP:</th><th align=left>",
  270.           &radio('eftp',$val{'eftp'},'Yes','No'),
  271.           "</th></tr>";
  272.  
  273.     if ($val{'dto'} == 900) { $val{'dto'} = ""; }
  274.     print "<tr><th align=left>Idle time before connection is dropped
  275.             (seconds):</th><th align=left>",
  276.           &text('dto', $val{'dto'},10),
  277.           "</th></tr>";
  278.  
  279. #    print '<TR><TH ALIGN="left">Maximum Inactivity Timeout (seconds)',
  280. #            '<TH ALIGN="left">';
  281. #    print &text('mto', $mto);
  282.  
  283.     print "<tr><th align=left>Log events in FTP sessions:</th><th align=left>",
  284.           &radio('logf',$val{'logf'},'Yes','No'),
  285.           "</th></tr>";
  286.  
  287.     print "<tr><th align=left>Permission settings for new files:",
  288.           "</th><th></th></tr>";
  289.  
  290.     print "</table></center>\n";
  291.  
  292.     if ($val{'or'} eq "") { $chor = "checked"; } else { $chor = ""; }
  293.     if ($val{'ow'} eq "") { $chow = "checked"; } else { $chow = ""; }
  294.     if ($val{'oe'} eq "") { $choe = "checked"; } else { $choe = ""; }
  295.  
  296.     if ($val{'gr'} eq "") { $chgr = "checked"; } else { $chgr = ""; }
  297.     if ($val{'gw'} eq "") { $chgw = "checked"; } else { $chgw = ""; }
  298.     if ($val{'ge'} eq "") { $chge = "checked"; } else { $chge = ""; }
  299.  
  300.     if ($val{'tr'} eq "") { $chtr = "checked"; } else { $chtr = ""; }
  301.     if ($val{'tw'} eq "") { $chtw = "checked"; } else { $chtw = ""; }
  302.     if ($val{'te'} eq "") { $chte = "checked"; } else { $chte = ""; }
  303.  
  304.     print "<center><table><tr><td></td><td>Owner</td><td>Group</td>
  305.             <td>Other</td></tr>";
  306.  
  307.     print "<tr><td>Read</td>";
  308.     print "<td>",qq|<input type="checkbox" name="or" $chor>|,"</td>";
  309.     print "<td>",qq|<input type="checkbox" name="gr" $chgr>|,"</td>";
  310.     print "<td>",qq|<input type="checkbox" name="tr" $chtr>|,"</td>";
  311.     print "</tr>";
  312.  
  313.     print "<tr><td>Write</td>";
  314.     print "<td>",qq|<input type="checkbox" name="ow" $chow>|,"</td>";
  315.     print "<td>",qq|<input type="checkbox" name="gw" $chgw>|,"</td>";
  316.     print "<td>",qq|<input type="checkbox" name="tw" $chtw>|,"</td>";
  317.     print "</tr>";
  318.  
  319.     print "<tr><td>Execute</td>";
  320.     print "<td>",qq|<input type="checkbox" name="oe" $choe>|,"</td>";
  321.     print "<td>",qq|<input type="checkbox" name="ge" $chge>|,"</td>";
  322.     print "<td>",qq|<input type="checkbox" name="te" $chte>|,"</td>";
  323.     print "</tr>";
  324.  
  325.     print "</table></center><br>";
  326.  
  327.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"');
  328.  
  329.     print "</form>";
  330. }
  331.